CS 5010: Problem Set 03: Iterative Design

Out: Monday, September 26, 2016

Due: Monday, October 3, 2016 at 600pm local time

The goal of this problem set is to help you design functions that deal with the Universe model, and to give you practice with the Iterative Design Recipe.

You will also get experience with the Perfect Bounce and Smooth Dragging, which we will be using in many of our exercises.

You must use the HtDP Beginning Intermediate Student Language to solve the problems.

For these problems, download a copy of extras.rkt and put it in the folder with your solutions. Then import this library by including the line

(require "extras.rkt")
at the top of your file with the other requires. Also, be sure to include extras.rkt in the folder that you submit. Then, for each problem, put in lines that say
(provide function)
for each deliverable function, as you have done on previous problem sets. This will allow our testing framework to import your file and do automated testing on it. You can use check-location, as you did on the preceding problem set, to double-check that your solutions are in the right place.

Remember that you must follow the design recipe. Your deliverables include the data definitions (including interpretation and templates), contract and purpose header, code, and tests. Be sure to follow our coding conventions. This will make the TA's job much easier.

Be sure to sync your work and fill out a Work Session Report at the end of every work session. Use the Work Session Report for PS03.

Note: For all universe programs, you may assume that the mouse is never dragged or moved outside of the canvas. Once the mouse enters the canvas, if the mouse ever leaves the canvas, then the behavior of your system is unspecified.


  1. (screensaver-1). Your boss has assigned you to a project to build a screensaver. The specifications for the screensaver are as follows:

    Here's a demo:

    You are to deliver a file named screensaver-1.rkt that provides the following functions:

    ;; screensaver : PosReal -> WorldState
    ;; GIVEN: the speed of the simulation, in seconds/tick
    ;; EFFECT: runs the simulation, starting with the initial state as
    ;; specified in the problem set.
    ;; RETURNS: the final state of the world
    
    ;; initial-world : Any -> WorldState
    ;; GIVEN: any value (ignored)
    ;; RETURNS: the initial world specified in the problem set
    
    ;; world-after-tick : WorldState -> WorldState
    ;; RETURNS: the world state that should follow the given world state
    ;; after a tick.
    
    ;; world-after-key-event : WorldState KeyEvent -> WorldState
    ;; RETURNS: the WorldState that should follow the given worldstate
    ;; after the given keyevent
    
    ;; world-circ1 : WorldState -> Circle
    ;; world-circ2 : WorldState -> Circle
    ;; world-paused? : WorldState -> Boolean
    ;; RETURNS: the specified attribute of the WorldState
    ;; NOTE: if these are part of the world struct, you don't need to
    ;; write any deliverables for these functions.
    
    ;; new-circle : NonNegInt NonNegInt Int Int -> Circle
    ;; GIVEN: 2 non-negative integers x and y, and 2 integers vx and vy
    ;; RETURNS: a circle centered at (x,y), which will travel with
    ;; velocity (vx, vy).
    
    ;; circ-x : Circle -> NonNegInt
    ;; circ-y : Circle -> NonNegInt
    ;; circ-vx : Circle -> Int
    ;; circ-vy : Circle -> Int
    ;; RETURNS: the coordinates of the center of the circle and its
    ;; velocity in the x- and y- directions.
    
  2. (screensaver-2). Your boss has now decided to build a better screensaver. This one is like the original, except for the following:

    Here's a demo:

    You are to deliver a file named screensaver-2.rkt that provides all the functions above, plus the following:

    ;; world-after-mouse-event
    ;;  : WorldState Int Int MouseEvent -> WorldState
    ;; GIVEN: A World, the x- and y-coordinates of a mouse event, and the
    ;; mouse event
    ;; RETURNS: the world that should follow the given world after the given mouse
    ;; event.
    
    ;; circ-after-mouse-event :  Circle Int Int MouseEvent -> Circle
    ;; GIVEN: A circle, the x- and y-coordinates of a mouse event, and the
    ;; mouse event
    ;; RETURNS: the circle that should follow the given circle after
    ;; the given mouse event
    
    ;; circ-selected? : Circle -> Boolean
    ;; RETURNS: true iff the given circle is selected.
    
    ;; new-circle
    ;; as before, but now it returns an UNSELECTED circle.
    

Last modified: Wed Sep 28 21:16:23 Eastern Daylight Time 2016